This module defines a class for simple self_organizing_map (one kohonen layer)
Class to represent a self_organizing_map
procedure, public :: create => create_som | |
procedure, public :: destroy => destroy_som | |
procedure, public :: train => train_som_data | |
procedure, public :: predict => predict_som | |
procedure, public :: print => print_som | |
procedure, public :: read => read_som | |
procedure, public :: get_count => get_count_som | |
procedure, public :: query => query_som | |
procedure, public :: get_prototypes | |
procedure, public :: get_u_matrix => get_u_matrix_som | |
procedure, public, nopass :: external_train_map | |
procedure, public, nopass :: external_predict_map |
Function to calculate the index inside a rectangular grid from position ix,iy,iz
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | ix |
Integer variables |
||
integer, | intent(in) | :: | iy |
Integer variables |
||
integer, | intent(in) | :: | iz |
Integer variables |
||
integer, | intent(in) | :: | nx |
Integer variables |
||
integer, | intent(in) | :: | ny |
Integer variables |
Integer variable with the required index
Function to calculate the scaling factor sigma
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
real(kind=wp), | intent(inout), | dimension(:,:) | :: | input_data |
A real array with the input data |
|
integer, | intent(inout), | optional | :: | seed |
An integer with the random seed |
A real variable with the value of sigma
Constructor for self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
type(kohonen_layer_parameters), | dimension(:) | :: | training_parameters |
A |
Destructor for self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
Subroutine to generate random values that serve as inputs to the SOM
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
real(kind=wp), | intent(out), | dimension(:,:) | :: | input |
A real array with the initial values of the prototypes |
Training function for self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
type(kohonen_pattern), | intent(inout), | dimension(:) | :: | input_data |
A |
Function for Prediction of a self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
type(kohonen_pattern), | intent(inout), | dimension(:) | :: | input_data |
A |
|
integer, | intent(out), | dimension(:,:) | :: | map_output |
An integer array with the map output |
Print function for self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map | ||||
integer, | intent(inout), | optional | :: | unit_ |
Function to get count matrix for self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map | ||||
integer, | intent(inout), | dimension(:,:,:) | :: | count_ |
Function to find the input samples associated with specific vector
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map | ||||
real(kind=wp), | intent(inout), | dimension(:,:) | :: | input_pattern | ||
integer, | allocatable | :: | sample_index(:) |
Subroutine to read the prototypes to define a self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
character(len=*) | :: | som_fl |
A character variable with the name of the file |
Subroutine to calculate the position ix,iy,iz inside a rectangular grid from index
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | index_ |
Integer variable representing the index |
||
integer, | intent(in) | :: | nx |
Integer variables representing the dimensions of the kohonen map |
||
integer, | intent(in) | :: | ny |
Integer variables representing the dimensions of the kohonen map |
||
integer, | intent(in) | :: | nz |
Integer variables representing the dimensions of the kohonen map |
||
integer, | intent(inout) | :: | cx |
Integer variables representing the position of the node |
||
integer, | intent(inout) | :: | cy |
Integer variables representing the position of the node |
||
integer, | intent(inout) | :: | cz |
Integer variables representing the position of the node |
Subroutine to calculate the distance between the units inside a kohonen layer
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(inout), | dimension(:,:) | :: | coordinates |
Real array with the coordinates |
|
real(kind=wp), | intent(inout), | dimension(:,:) | :: | distance_matrix |
Real array with the distance_matrix |
|
character(len=*) | :: | grid_type |
Character variable with the grid type |
|||
logical | :: | toroidal |
Logical variable for toroidal grid |
Subroutine to calculate the coordinates of the units inside a kohonen layer
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | current_index | |||
integer, | intent(in) | :: | ix | |||
integer, | intent(in) | :: | iy | |||
integer, | intent(in) | :: | iz | |||
integer, | intent(in) | :: | nx | |||
integer, | intent(in) | :: | ny | |||
integer, | intent(in) | :: | nz | |||
real(kind=wp), | intent(out), | dimension(:,:) | :: | coordinates | ||
character(len=*), | intent(in) | :: | node_type |
Subroutine to calculate the best match unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
type(kohonen_prototype), | intent(inout) | :: | current_prototype |
A |
||
integer, | intent(out) | :: | ihit |
Integer variables for the coordinates of the BMU |
||
integer, | intent(out) | :: | jhit |
Integer variables for the coordinates of the BMU |
||
integer, | intent(out) | :: | khit |
Integer variables for the coordinates of the BMU |
||
real(kind=wp), | intent(out) | :: | dist_hit |
Real variable with the distance to the BMU |
Subroutine to update the weights
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
real(kind=wp), | intent(inout), | dimension(:,:) | :: | current_values |
A real array with the values of the current unit |
|
integer, | intent(inout) | :: | ihit |
Integer variables with the coordinates of the unit (neuron) to be modified |
||
integer, | intent(inout) | :: | jhit |
Integer variables with the coordinates of the unit (neuron) to be modified |
||
integer, | intent(inout) | :: | khit |
Integer variables with the coordinates of the unit (neuron) to be modified |
||
real(kind=wp), | intent(inout) | :: | maximum_radius |
Real variable with the maximum radius of the neighborhood |
||
integer, | intent(inout) | :: | iteration |
Integer variables with the coordinates of the unit (neuron) to be modified |
Subroutine to calculate the distance between the prototypes
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
Subroutine to calculate the best match unit over the grid
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
type(kohonen_pattern), | intent(inout), | dimension(:) | :: | input_data |
A |
Subroutine to calculate the u_matrix
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
Subroutine to calculate the u_matrix for an hexagonal grid
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
Subroutine to calculate the u_matix for a rectangular grid
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
Subroutine to get the u_matrix from a SOM
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
real(kind=wp), | intent(out), | dimension(:,:,:) | :: | u_matrix |
A real array to return the u_matrix |
Subroutine to get SOM prototypes
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
real(kind=wp), | intent(out), | dimension(:,:) | :: | prototypes |
A real array to return the values of the SOM prototypes |
Subroutine to connect the self_organizing_map module to R o C Import section
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=c_double), | intent(in) | :: | x(npat,nvar) |
Real array with the input patterns |
||
integer(kind=c_int), | intent(in) | :: | nvar |
Integer variables to indicate the number of variables and patterns |
||
integer(kind=c_int), | intent(in) | :: | npat |
Integer variables to indicate the number of variables and patterns |
||
integer(kind=c_int), | intent(in) | :: | nx |
Integer variables to indicate the number of nodes of the SOM |
||
integer(kind=c_int), | intent(in) | :: | ny |
Integer variables to indicate the number of nodes of the SOM |
||
integer(kind=c_int), | intent(in) | :: | nepoch |
Integer variables to indicate the number of epochs for training |
||
real(kind=c_double), | intent(in) | :: | alpha |
Real value with the initial learning rate |
||
integer(kind=c_int), | intent(in) | :: | grid_type |
Integer variable to indicate the type of grid |
||
integer(kind=c_int), | intent(in) | :: | distance_type |
Integer variable to indicate the distance type |
||
integer(kind=c_int), | intent(in) | :: | neigh_type |
Integer variable to indicate the neighborhood type |
||
integer(kind=c_int), | intent(in) | :: | toroidal |
Integer variable to indicate if a toroidal grid is used |
||
real(kind=c_double), | intent(out) | :: | prot(nx*ny,nvar) |
Real array for the prototypes |
||
real(kind=c_double), | intent(out) | :: | distortion(nepoch) |
Real array for the distortion measure (error during training) |
||
real(kind=c_double), | intent(out) | :: | u_matrix(2*nx-1,2*ny-1) |
Real array for the u_matrix |
||
real(kind=c_double), | intent(out) | :: | coords(nx*ny,3) |
Real array for the grid coordinates of the SOM |
||
integer(kind=c_int), | intent(out) | :: | number_patterns(nx,ny) |
Integer array with the number of hits for each neuron |
||
integer(kind=c_int), | intent(out) | :: | node_index(npat,3) |
Integer array with the index node for all the neurons of the SOM |
Subroutine to connect this module to R
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=c_double), | intent(in) | :: | prot(nx*ny,nvar) | |||
integer(kind=c_int), | intent(in) | :: | nx | |||
integer(kind=c_int), | intent(in) | :: | ny | |||
real(kind=c_double), | intent(in) | :: | new_pat(npat,nvar) | |||
integer(kind=c_int), | intent(in) | :: | npat | |||
integer(kind=c_int), | intent(in) | :: | nvar | |||
integer(kind=c_int), | intent(out) | :: | node_index(npat,3) |